var cTypeHelper = {}
cTypeHelper.baseTypes = {}

var returnSelf = function(param)
{
    return param
}

var baseTypes = cTypeHelper.baseTypes

baseTypes.WORD =
{
    size:2,
    toUInt:returnSelf
}

baseTypes.TCHAR =
{
    size:2,
    toUInt:function(param)
    {
        return param.charCodeAt(0)
    }
}

baseTypes.UINT =
{
    size:4,
    toUInt:returnSelf
}

baseTypes.BYTE =
{
    size:1,
    toUInt:returnSelf
}

baseTypes.DWORD =
{
    size:4,
    toUInt:returnSelf
}

baseTypes.LONG =
{
    size:8,
    toUInt:returnSelf
}


//参数是类型对象
cTypeHelper.getTypeSize = function(type)
{
    return isParent(type, cTypeHelper.baseTypes)?type.size:cTypeHelper.getStructSize(type)
}

sizeof = cTypeHelper.getTypeSize

//参数是类型对象
cTypeHelper.getStructSize = function(type)
{     
    try
    {   
        var size = 0
        var struct = type
        for(var i=0;i<struct.length;i++)
        {
            var subStruct = struct[i]
            if(cTypeHelper.baseTypes[subStruct[0]])
                var sizet = cTypeHelper.getTypeSize(cTypeHelper.baseTypes[subStruct[0]])
            else
                var sizet = cTypeHelper.getTypeSize(eval(subStruct[0]))

            for(var j=2;j<subStruct.length;j++)
            {
                sizet = sizet * subStruct[j]
            }
            size = size + sizet
        }
        return  size
    }
    catch(e)
    {
        return  'unidentified typeName' 
    }   
}

cTypeHelper.struct2Obj = function(typeName)
{
    try
    {   
        var struct = eval(typeName)
        var obj = {}
        for(var i=0;i<struct.length;i++)
        {
            var subStruct = struct[i]
            obj[subStruct[1]] = null
        }
        return obj
    }
    catch(e)
    {
        return  'unidentified typeName' 
    }     
}
